package com.supermap.localization.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.supermap.localization.commontypes.LocationInfo;
import com.supermap.localization.commontypes.SampleInfo;

public class MapUtil {
    public static void addSampleInfoList(Map<String, SampleInfo> map, List<SampleInfo> samples) {
        for (int i = 0; i < samples.size(); i++) {
            SampleInfo info = samples.get(i);
            if (map.containsKey(info.getKey())) {
                SampleInfo currentInfo = map.get(info.getKey());
                List<LocationInfo> extLocations = info.getLocation();
                for (int j = 0; j < extLocations.size(); j++) {
                    currentInfo.addLocation(extLocations.get(j));
                }
            } else {
                map.put(info.getKey(), info);
            }
        }
    }

    public static List<SampleInfo> convertToList(Map<String, SampleInfo> map) {
        return new ArrayList<>(map.values());
    }
}
